//
//  ZJProjectInfoVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/29.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJProjectInfoVC.h"
#import "ZJProjectInfoCell.h"
@interface ZJProjectInfoVC ()<MWPhotoBrowserDelegate>


/**<数据模型>*/

@property (strong, nonatomic) NSDictionary * modelDic;
@end

@implementation ZJProjectInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];


    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZJProjectInfoCell class]) bundle:nil] forCellReuseIdentifier:@"ZJProjectInfoCell"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickBtn:) name:@"clickLicence" object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"clickLicence" object:nil];
    
}

-(void)clickBtn:(NSNotification*)notification{
    
    NSDictionary * dict = [notification object];
    
    NSArray * arr = self.model.licence;
    
    for (NSDictionary * dic in arr) {
        if ([dic[@"licence_name"] isEqualToString:dict[@"name"]]) {
            self.modelDic = dic;
        }
    }
    
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    // Set options
    browser.displayActionButton = NO;
    [browser showNextPhotoAnimated:YES];
    [browser showPreviousPhotoAnimated:YES];
    [browser setCurrentPhotoIndex:0];

    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser];
    
    nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:nc animated:YES completion:nil];
}
#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
{
    return 1;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
{
    return [MWPhoto photoWithURL:[NSURL URLWithString:self.modelDic[@"pic_url"]]];
}

- (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJProjectInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJProjectInfoCell"];

    cell.model = self.model;
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGFloat height = [self.tableView cellHeightForIndexPath:indexPath model:self.model keyPath:@"model" cellClass:[ZJProjectInfoCell class] contentViewWidth:[Utils cellContentViewWith]];
    
    return height;;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
